﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DataShow.work
{
    public partial class WorkSheet : System.Web.UI.Page
    {
        #region 页面初加载事件
        /// <summary>
        /// 页面初加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            this.anp.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["pagesize"]);
            if (!IsPostBack)
            {
                Search();
            }
        } 
        #endregion

        #region 加载工作表
        /// <summary>
        /// 加载工作表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_search_all_Click(object sender, EventArgs e)
        {
            Search();
        } 
        #endregion

        #region 搜索人员绑定GridView
        /// <summary>
        /// 搜索人员绑定GridView
        /// </summary>
        private void Search()
        {
            int pagesize = anp.PageSize;
            int pageindex = anp.CurrentPageIndex;
            anp.RecordCount = new codeBLL.WorkBLL().CalculateCount();
            gv_result.DataSource = new codeBLL.WorkBLL().Search(pagesize, pageindex);
            gv_result.DataBind();
            if (anp.RecordCount == 0)
            {
                gv_result.Visible = false;
                anp.Visible = false;
                div_nodata.Visible = true;
            }
            else
            {
                gv_result.Visible = true;
                anp.Visible = true;
                div_nodata.Visible = false;
            }
        } 
        #endregion


        #region 删除选中工作表安排
        /// <summary>
        /// 删除选中工作表安排
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_delete_Click(object sender, EventArgs e)
        {
            List<string> IDS = new List<string>();//要删除的ID
            CheckBox cb = null;
            Label lbl_id = null;
            foreach (GridViewRow item in gv_result.Rows)
            {
                cb = item.FindControl("Select") as CheckBox;
                if (cb.Checked)
                {
                    lbl_id = item.FindControl("ID") as Label;
                    IDS.Add(lbl_id.Text);
                }
            }
            new codeBLL.WorkBLL().Delete(IDS);
            if (anp.CurrentPageIndex == anp.PageCount)
            {
                anp.CurrentPageIndex = 1;
            }
            Search();
        } 
        #endregion

        #region 翻页事件（重新绑定GridView）
        /// <summary>
        /// 翻页事件（重新绑定GridView）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void anp_PageChanged(object sender, EventArgs e)
        {
            Search();
        } 
        #endregion

        #region 处理全选功能
        /// <summary>
        /// 处理全选功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_check_all_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow item in gv_result.Rows)
            {
                (item.FindControl("Select") as CheckBox).Checked = true;
            }
        } 
        #endregion
    }
}